using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Acms.WebControls;

public partial class Templates_IssueTemplate : BaseTemplate
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ((BaseMaster)this.Page.Master).SetTopicTitle(CurrentPost.DisplayName);
            try
            {
                selectTopicId = int.Parse(Request.QueryString["SelectedTopic"]);
            }
            catch
            {
            }
        }
    }

    private int selectTopicId;


    protected void dlArticles_PageIndexChanged(object sender, EventArgs e)
    {
        ((Acms.WebControls.AcmsDataList)sender).SelectedIndex = 0;
    }

    protected void dsPosts_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.Post> e)
    {
        int topicId = (int)dlTopics.DataKeys[dlTopics.SelectedIndex]["Id"];
        int totalRecords = 0;
        System.Collections.Generic.List<Acms.Bll.Post> tmp = Acms.Bll.Post.GetAllByParentIdAndTopicId(CurrentPost.Id, topicId, false, e.StartRowIndex, e.MaximumRecords, ref totalRecords);
        e.SetData(tmp, totalRecords);
    }

    protected void dsTopics_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.Topic> e)
    {
        List<Acms.Bll.Topic> tmp = Acms.Bll.Topic.GetAllBySiteId(CurrentSiteId);
        if (!Page.IsPostBack && selectTopicId > 0)
        {
            for (int i = 0; i < tmp.Count; i++)
            {
                if (tmp[i].Id == selectTopicId)
                {
                    dlTopics.SelectedIndex = i;
                }
            }
        }
        e.SetData(tmp);
    }

    protected void dlTopics_ItemDataBound(object sender, AcmsDataListItemEventArgs e)
    {
        if (e.Item.IsSelectedItem)
        {
            Master.SetTopic(e.Item.DataItem as Acms.Bll.Topic);
        }
    }
}
